package ua.lviv.franko.visualisation;

import java.awt.Dimension;

import org.jzy3d.chart.Chart;
import org.jzy3d.colors.Color;
import org.jzy3d.colors.ColorMapper;
import org.jzy3d.colors.colormaps.ColorMapRainbow;
import org.jzy3d.maths.Range;
import org.jzy3d.plot3d.builder.Builder;
import org.jzy3d.plot3d.builder.Mapper;
import org.jzy3d.plot3d.builder.concrete.OrthonormalGrid;
import org.jzy3d.plot3d.primitives.Shape;
import org.jzy3d.plot3d.rendering.canvas.Quality;
import org.jzy3d.plot3d.rendering.legends.colorbars.ColorbarLegend;
import org.jzy3d.ui.ChartLauncher;

public class Visualise3D {
	public static void show(Mapper mapper, Range xrange, Range yrange) {
		int nsteps = 25;

		final Shape surface = (Shape) Builder.buildOrthonormal(new OrthonormalGrid(xrange, nsteps, yrange, nsteps), mapper);
		surface.setColorMapper(new ColorMapper(new ColorMapRainbow(), surface.getBounds().getZmin(), surface.getBounds().getZmax(), new Color(1, 1, 1, .5f)));
		surface.setFaceDisplayed(true);
		surface.setWireframeDisplayed(true);
		surface.setWireframeColor(Color.BLACK);

		// Create a chart and add surface
		Chart chart = new Chart(Quality.Advanced);
		chart.getScene().getGraph().add(surface);

		// Setup a colorbar
		ColorbarLegend cbar = new ColorbarLegend(surface, chart.getView().getAxe().getLayout());
		cbar.setMinimumSize(new Dimension(100, 600));
		surface.setLegend(cbar);

		ChartLauncher.openChart(chart);

	}
}
